import json
import logging

from django.http import JsonResponse
from django.shortcuts import render
import datetime
import time
import random

logger = logging.getLogger("log")


def hello(request, _):
    """
    获取当前计数

     `` request `` 请求对象
    """
    d = {"code": 0, "data": "hello yunkaifa"}
    logger.info(d)
    logger.info(request)

    return JsonResponse(d, json_dumps_params={"ensure_ascii": False})


def order_uuid(prefix):
    """
    :return: 20220525140635467912
    :PS ：并发较高时尾部随机数增加
    """
    order_id = (
        str(prefix)
        + str(datetime.datetime.fromtimestamp(time.time()))
        .replace("-", "")
        .replace(" ", "")
        .replace(":", "")
        .replace(".", "")
        + str(random.randint(100, 999))
    )
    return order_id
